﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class UserData_Device : UserData
	{
		#region private member variables

		private readonly byte _device;

		#endregion private member variables

		#region constructor

		public UserData_Device(byte dataType, byte device) : base(dataType)
		{
			_device = device;
		}

		#endregion constructor

		#region getters

		public byte Device { get { return _device; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();
			hashCode ^= Device;
			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());

			stringBuilder.Append(", ");

			stringBuilder.Append("Device='");
			stringBuilder.Append("0x");
			stringBuilder.Append(Device.ToString("X2"));
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData_Device userData2Compare = obj as UserData_Device;
				if (base.EqualsProperties(userData2Compare))
				{
					return EqualsProperties(userData2Compare);
				}
			}

			return false;
		}

		internal bool EqualsProperties(UserData_Device userData2Compare)
		{
			return (this.Device == userData2Compare.Device);
		}

		#endregion ToString, Equals, GetHashCode
	}
}
